//
//  MallCartTableViewCell.m
//  CYWFrame
//
//  Created by Macx on 2017/9/7.
//  Copyright © 2017年 Macx. All rights reserved.
//

#import "MallCartTableViewCell.h"
#import "Goods.h"

@implementation MallCartTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    CGSize size1 = [LZCTools textSizeWithText:@"x" font:kUHSystemFontWithSize(12)];
    
    CGFloat btnW = 25.0;
    
    self.select.frame = CGRectMake(10, self.contentView.centerY-15, btnW, btnW);
//    [self.select setImage:[IMAGE(@"placeHolder") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [self.select setImage:[IMAGE(@"shop_car_unchose") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
//    [self.select setImage:[IMAGE(@"shop_car_chose") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateSelected];
    
    self.pic.frame = CGRectMake(self.select.width+self.select.x+10, 10, 2*SW(8), 2*SW(8));
    
    self.title.font = kUHSystemFontWithSize(12);
    self.title.frame = CGRectMake(self.pic.x+self.pic.width+10, 10, SCREEN_WIDTH-self.title.x-10, size1.height*2);
    self.title.numberOfLines = 2;
    
    self.reduce.layer.borderWidth = 1;
    self.reduce.layer.borderColor = kLightGrayColor.CGColor;
    self.reduce.frame = CGRectMake(self.title.x, self.pic.y+self.pic.height-25, btnW, btnW);
    
    self.num.font = kUHSystemFontWithSize(12);
    self.num.frame = CGRectMake(self.reduce.x+self.reduce.width-1, self.reduce.y, btnW+10, btnW);
    self.num.textAlignment = NSTextAlignmentCenter;
    self.num.layer.borderWidth = 1;
    self.num.layer.borderColor = kLightGrayColor.CGColor;
    
    self.increase.layer.borderWidth = 1;
    self.increase.layer.borderColor = kLightGrayColor.CGColor;
    self.increase.frame = CGRectMake(self.num.x+self.num.width-1, self.reduce.y, btnW, btnW);
    
    self.money.font = kUHSystemFontWithSize(12);
    self.money.frame = CGRectMake(SCREEN_WIDTH-10-SW(4), self.reduce.y, SW(4), 30);
    self.money.textAlignment = NSTextAlignmentRight;

}

- (void)setModel:(Goods *)model {
    
    if (_model != model) {
        _model = model;
        
        [self.pic sd_setImageWithURL:[NSURL URLWithString:[model valueForKey:@"photo"][0]] placeholderImage:IMAGE(@"placeHolder")];
        self.title.text = [NSString stringWithFormat:@"%@\n", [model valueForKey:@"title"]];
        if ([model valueForKey:@"selectedSku"]) {
            
            self.money.text = [NSString stringWithFormat:@"￥%.2lf", [[model valueForKey:@"selectedSku"][@"price"] floatValue]/100];
        }
        self.money.text = [NSString stringWithFormat:@"￥%.2lf", [[model valueForKey:@"price"] floatValue]/100];
        self.num.text = [NSString stringWithFormat:@"%@", [model valueForKey:@"quantity"]];
        if (model.selectedSpecs.count) {
            NSString *cateName = [model.selectedSpecs[0] valueForKey:@"name"];
            NSString *cateValue = [model.selectedSpecs[0] valueForKey:@"val"];
            self.category.text = [NSString stringWithFormat:@"%@: %@", cateName, cateValue];
            
            if (model.selectedSpecs.count >= 2) {
                NSString *specName = [model.selectedSpecs[1] valueForKey:@"name"];
                NSString *specValue = [model.selectedSpecs[1] valueForKey:@"val"];
                self.spec.text = [NSString stringWithFormat:@"%@: %@", specName, specValue];
            }
        }
        
    }
    
}

- (void)layoutSubviews {
//    if (self.isS) {
//        [self.select setImage:[IMAGE(@"login_tick") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateSelected];
//        }
//    else {
//        [self.select setImage:[IMAGE(@"login_un_tick") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
//    }
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
